<template>
  <div id="app">
    <router-view />
    <div id="nav">
      <Footer
        v-if="
          $route.path == '/' ||
          $route.path.match('/home') ||
          $route.path == '/video' ||
          $route.path == '/minivideo' ||
          $route.path == '/me'
        "
      ></Footer>
    </div>
    <div class="totop" v-if="topType" @click="goTop">返回顶部</div>
  </div>
</template>

<script>
import Footer from "./components/Footer.vue";

export default {
  name: "App",
  data() {
    return {
      topType: false,
      scrollTop: "",
    };
  },
  components: {
    Footer,
  },
  mounted() {
    console.log(this.$route.path);
    window.addEventListener("scroll", this.handleScroll);
  },
  //卸载
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
  },
  watch: {
    scrollTop() {
      if (this.scrollTop >= 300) {
        this.topType = true;
      } else {
        this.topType = false;
      }
    },
  },
  methods: {
    handleScroll() {
      this.scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      if (this.scrollTop >= 300) {
        this.topType = true;
      }
    },
    goTop() {
      console.log(11111)
      let timer = setInterval(() => {
        if(document.documentElement.scrollTop>0||document.body.scrollTop>0){
           document.documentElement.scrollTop -= 30;
          //  document.body.scrollTop -= 30;
           console.log(document.documentElement.scrollTop)
        }else if(document.documentElement.scrollTop<=0||document.body.scrollTop<=0){
          clearInterval(timer)
        }
      }, 50);
    },
  },
};
</script>

<style>
* {
  padding: 0;
  margin: 0;
}

body {
  background-color: rgb(247, 245, 245);
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

#nav a {
  color: #414549;
  text-decoration: none;
  font-size: 0.346667rem;
}

#nav a.router-link-active {
  color: #f03d37;
}

.totop {
  position: fixed;
  right: 0;
  bottom: 2.4rem;
  width: 2.2rem;
  height: 0.76rem;
  line-height: 0.76rem;
  z-index: 10;
  opacity: 0.94;
  background-image: linear-gradient(134deg, #fb3333, #ff5269 75%);
  box-shadow: 0 2px 4px 0 rgb(160 44 41 / 15%);
  border-radius: 20px 0 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
}
</style>